﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace Wicresoft.Shell.Core.Original
{
    public static class Logger
    {
        #region Fields

        private static IVsOutputWindowPane mS_LogWndPane;
        private static IVsWindowFrame _outputWindowFrame;

        #endregion

        #region Constructor

        static Logger()
        {
            mS_LogWndPane = null;
        }

        #endregion

        #region Methods

        public static void Output(string format, params object[] objs)
        {
            if (_outputWindowFrame == null)
            {
                Guid guid = new Guid(ToolWindowGuids.Outputwindow);
                IVsUIShell shell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;
                shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref guid, out _outputWindowFrame);
            }
            _outputWindowFrame.Show();


            if (null == mS_LogWndPane)
            {
                IVsOutputWindow outWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;

                if (null != outWindow)
                {
                    Guid generalWindowGuid = VSConstants.GUID_OutWindowGeneralPane;
                    outWindow.GetPane(ref generalWindowGuid, out mS_LogWndPane);
                }
            }

            if (null != mS_LogWndPane)
            {
                if (!format.EndsWith(Environment.NewLine))
                    format = format + Environment.NewLine;
                mS_LogWndPane.OutputString(String.Format(format, objs));
            }
        }

        #endregion
    }
}
